//
//  StockInOutController.swift
//  TestAPIManager
//
//  Created by yq on 2020/10/16.
//  Copyright © 2020 杨庆. All rights reserved.
//

import UIKit
import RxSwift

class StockInOutController: UIViewController,Ynibloadable {
    
    private let disBag = DisposeBag()
    
    @IBOutlet weak var menuView: StockInOutMenuView!
    @IBOutlet weak var contentScrollView: UIScrollView!
    @IBOutlet weak var inTableView: StockInOutTableView!
    @IBOutlet weak var outTableView: StockInOutTableView!
       
    let datas = ["入库数据","入库数据","入库数据","入库数据","入库数据","入库数据"]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let setupNav = {
            self.navigationController?.navigationBar.tintColor = .black
            self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
            self.navigationController?.navigationBar.subviews[0].subviews[0].isHidden = true
            self.navigationItem.title = "出入库"
        }
    
        let setupUI = {
            self.contentScrollView.delegate = self
            /*menu is granged*/
            self.menuView.isGanged = true
            self.menuView.inAction = { [weak self] in
                self?.contentScrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
            }
            self.menuView.outAction = { [weak self] in
                self?.contentScrollView.setContentOffset(CGPoint(x: (self?.contentScrollView.frame.size.width)!, y: 0), animated: true)
            }
        }
        
        let setupTableView = {
            self.inTableView.stockInOutVc = self
            self.outTableView.stockInOutVc = self
            self.inTableView.stockType = .stockIn
            self.outTableView.stockType = .stockOut
        }
        
        /*main function*/
        setupNav()
        setupUI()
        setupTableView()
    }
    
}


extension StockInOutController: UIScrollViewDelegate {
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
        let offsetX = scrollView.contentOffset.x
        let percent = offsetX / scrollView.frame.width
        menuView.updateBgViewProgress(with: percent)
    }
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        print("请求网络")
    }
}

